package com.zmn.plat.admin.controller.product.engineerexamineurl;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.zmn.common.dto2.ResponseDTO;
import com.zmn.common.utils.date.DateUtil;
import com.zmn.plat.model.entity.product.engineerexamineurl.EngineerExamineUrl;
import com.zmn.plat.services.interfaces.product.engineerexamineurl.EngineerExamineUrlService;

/**
 * 工程师升级考试地址基础修改Controller
 *
 * @author tanghongjun
 * @since 2020-08-19 11:18:36
 */
@RestController
@RequestMapping("/product/engineerexamineurl")
public class EngineerExamineUrlModifyController extends EngineerExamineUrlBaseController {
    private Logger logger = LoggerFactory.getLogger(EngineerExamineUrlListController.class);

    @Autowired
    private EngineerExamineUrlService engineerExamineUrlService;

    /**
     * 保存
     */
    @RequestMapping("/addEdit")
    @RequiresPermissions("/product/engineerexamineurl/addEdit.action")
    public ResponseDTO addEdit(HttpServletRequest request, @RequestBody EngineerExamineUrl engineerExamineUrl) {

        Date now = DateUtil.getNow();
        int relateId = engineerExamineUrl.getRelateId();
        try {
            if (relateId == 0) {
                engineerExamineUrl.setCreater(getMcStaffRealName());
                engineerExamineUrl.setCreateTime(now);
                engineerExamineUrl.setUpdater(getMcStaffRealName());
                engineerExamineUrl.setUpdateTime(now);
                engineerExamineUrlService.insert(engineerExamineUrl);
            } else {
                engineerExamineUrl.setUpdater(getMcStaffRealName());
                engineerExamineUrl.setUpdateTime(now);
                engineerExamineUrlService.updateByKey(engineerExamineUrl);
            }

            return ResponseDTO.success(true, "配置成功！");
        } catch (Exception e) {
            logger.error("新增/修改失败,Exception{},msg{}", e, e.getMessage());
            return ResponseDTO.fail("配置失败！");
        }
    }

}
